#DighitDraw.py
import turtle
import time

#v1绘制线函数
def drawLine(line):
    turtle.pendown() if line else turtle.penup()
    turtle.fd(40)
    turtle.right(90)
#v1绘制数字函数
def drawDigit(num):
    drawLine(True) if num in [2,3,4,5,6,8,9] else drawLine(False)
    drawLine(True) if num in [0,1,3,4,5,6,7,8,9] else drawLine(False)
    drawLine(True) if num in [0,2,3,5,6,8,9] else drawLine(False)
    drawLine(True) if num in [0,2,6,8] else drawLine(False)
    turtle.left(90)
    drawLine(True) if num in [0,4,5,6,8,9] else drawLine(False)
    drawLine(True) if num in [0,2,3,5,6,7,8,9] else drawLine(False)
    drawLine(True) if num in [0,1,2,3,4,7,8,9] else drawLine(False)
    turtle.right(180)
    turtle.penup()
    turtle.fd(20)
#v1绘制日期函数
def drawDate(date):
    for i in date:
        drawDigit(eval(i))
#v1绘制总函数
def v1DigitDraw():
    turtle.setup(800,350,200,200)
    turtle.penup()
    turtle.fd(-200)
    turtle.pensize(5)
    drawDate('20191231')
    turtle.hideturtle()
    turtle.done()

#v2绘制间隔
def drawGap():
    turtle.penup()
    turtle.fd(5)
#v2绘制线函数
def drawLines(line):
    drawGap()
    turtle.pendown() if line else turtle.penup()
    turtle.fd(40)
    drawGap()
    turtle.right(90)
#v2绘制数字函数
def drawDigits(num):
    drawLines(True) if num in [2,3,4,5,6,8,9] else drawLines(False)
    drawLines(True) if num in [0,1,3,4,5,6,7,8,9] else drawLines(False)
    drawLines(True) if num in [0,2,3,5,6,8,9] else drawLines(False)
    drawLines(True) if num in [0,2,6,8] else drawLines(False)
    turtle.left(90)
    drawLines(True) if num in [0,4,5,6,8,9] else drawLines(False)
    drawLines(True) if num in [0,2,3,5,6,7,8,9] else drawLines(False)
    drawLines(True) if num in [0,1,2,3,4,7,8,9] else drawLines(False)
    turtle.right(180)
    turtle.penup()
    turtle.fd(20)
#v2绘制日期函数
def drawDates(date):
    turtle.pencolor("blue")
    for i in date:
        if i == '-':
            turtle.write('年',font=("Arial",24,"normal"))
            turtle.pencolor("yellow")
            turtle.fd(40)
        elif i == '=':
            turtle.write('月',font=("Arial",24,"normal"))
            turtle.pencolor("red")
            turtle.fd(40)
        elif i == '+':
            turtle.write('日',font=("Arial",24,"normal"))
            turtle.fd(40)
        else:
            drawDigits(eval(i))

#v2绘制总函数
def v2DigitDraw():
    turtle.setup(800,350,200,200)
    turtle.penup()
    turtle.fd(-320)
    turtle.pensize(5)
    drawDates(time.strftime("%Y-%m=%d+",time.gmtime()))
    turtle.hideturtle()
    turtle.done()

v2DigitDraw()